using Exploder.Utils;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace Exploder.Demo
{
	public class DemoSimple : MonoBehaviour
	{
		private ExploderObject Exploder;

		private GameObject[] DestroyableObjects;

		private void Start()
		{
			Exploder = ExploderSingleton.ExploderInstance;
			if (Exploder.DontUseTag)
			{
				Object[] array = UnityEngine.Object.FindObjectsOfType(typeof(Explodable));
				List<GameObject> list = new List<GameObject>(array.Length);
				list.AddRange(from Explodable ex in array
					where ex
					select ex.gameObject);
				DestroyableObjects = list.ToArray();
			}
			else
			{
				DestroyableObjects = GameObject.FindGameObjectsWithTag("Exploder");
			}
		}

		private void OnGUI()
		{
			if (GUI.Button(new Rect(10f, 10f, 100f, 30f), "Explode!") && (bool)Exploder)
			{
				Exploder.ExplodeRadius();
			}
			if (!GUI.Button(new Rect(130f, 10f, 100f, 30f), "Reset"))
			{
				return;
			}
			ExploderUtils.SetActive(Exploder.gameObject, status: true);
			if (!Exploder.DestroyOriginalObject)
			{
				GameObject[] destroyableObjects = DestroyableObjects;
				foreach (GameObject obj in destroyableObjects)
				{
					ExploderUtils.SetActiveRecursively(obj, status: true);
				}
				ExploderUtils.SetActive(Exploder.gameObject, status: true);
			}
		}
	}
}
